<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
//use Illuminate\Support\Facades\Schema;

class AddTable20231025 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('tcm_book')) {
            Schema::create('tcm_book', function (Blueprint $table) {
                $table->id();
                $table->string('author')->default('')->comment('作者');
                $table->string('dynasty')->default('')->comment('朝代');
                $table->string('name')->index()->comment('书名');
                $table->string('img')->default('')->comment('图片');
                $table->string('share_img')->default('')->comment('分享图片');
                $table->integer('sort')->default(0)->comment('排序值');
                $table->tinyInteger('sound')->default(0)->comment('是否有声音');
                $table->tinyInteger('status')->default(1)->comment('状态 0-禁用 1-正常');
                $table->timestamps();
                $table->comment = '中医书籍';
            });
        }

        if (!Schema::hasTable('tcm_book_chapters')) {
            Schema::create('tcm_book_chapters', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('book_id')->index()->comment('书籍ID');
                $table->string('name')->index()->comment('章节名称');
                $table->tinyInteger('playable')->default(0)->comment('是否可以播放');
                $table->string('subhead')->index()->default('')->comment('副章节名称');
                $table->string('volume')->default('')->comment('卷');
                $table->string('audio')->nullable()->comment('音频');
                $table->longText('content')->nullable()->comment('内容');
                $table->integer('sort')->default(0)->comment('排序值');
                $table->comment = '中医书籍章节';
            });
        }

        if (!Schema::hasTable('tcm_book_collect')) {
            Schema::create('tcm_book_collect', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('book_id')->index()->comment('书籍ID');
                $table->unsignedInteger('member_id')->index()->comment('用户ID');
                $table->unsignedBigInteger('history_book_chapter_id')->default(0)->comment('已读历史章节ID');
                $table->comment = '用户书架';
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
